<template>
	<view>
		<view class="all">
			<!-- 输入框头部图标 -->
			<uni-easyinput prefixIcon="person" v-model="user.username" placeholder="请输入账号" @iconClick="onClick"></uni-easyinput>
			<!-- 展示输入框尾部图标 -->
			<uni-easyinput prefixIcon="info-filled" type="password" v-model="user.password" placeholder="请输入密码"></uni-easyinput>
			<button class="mini-btn cli_c" style="margin-top: 50rpx;width: 300rpx;height: 80rpx;font-size: 35rpx;"@click="login()" type="primary" size="mini">登录</button>
		</view>
	</view>
</template>

<script>
import bill from '../../api/pay.js';
export default {
	data() {
		return {
			user: {
				username: '',
				password: ''
			}
		};
	},
	methods: {
		login() {
			bill.login(this.user).then(res => {
				try {
					uni.setStorageSync('token', res.data.data.token);
					const token = uni.getStorageSync('token', res.data.data.token);
					if (token != null) {
						// 跳转到 tabBar 页面只能使用 switchTab 跳转
						uni.switchTab({
							url: '/pages/index/index'
						});
					}
				} catch (e) {
					// error
				}
			});
		}
	}
};
</script>

<style scoped lang="less">
.all {
	margin: 50rpx;
	padding: 20rpx;
	display: flex;
	flex-direction: column;
	align-items: center;
}
</style>
